<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Home\Model;
use Think\Model;

/**
 * Description of LotteryGoodsInfoModel
 *
 * @author Dark
 */
class LotteryGoodsInfoModel extends Model {
    
    /*
     * 增加一条拼购商品信息
     */
    public function addInfo($data) {
        $this->create();
        return $this->add($data);
    }
    
    /*
     * 更新一条拼购商品信息通过商品ID
     */
    public function updateByGoodsID($goodsID,$data) {
        if(!empty($goodsID)&&!empty($data)) {
            return $this->where('goods_ID='.$goodsID)->save($data);
        } else {
            return false;
        }
    }
    
    /*
     * 删除拼购商品信息通过商品ID
     */
    public function deleteByGoodsID($goodsID) {
        if(!empty($goodsID)) {
            return $this->where('ID='.$goodsID)->delete();
        } else {
            return false;
        }
    }
    
    /*
     * 删除拼购商品信息通过信息ID
     */
    public function deleteByInfoID($ID) {
        if(!empty($ID)) {
            return $this->where('ID='.$ID)->delete();
        } else {
            return false;
        }
    }
    
    /*
     * 查询所有拼购商品信息
     */
    public function queryAll() {
        return $this->select();
    }
    
    /*
     * 查询拼购商品信息通过商品ID
     */
    public function queryByGoodsID($goodsID) {
        if(!empty($goodsID)) {
            return $this->where('goods_ID='.$goodsID)->select();
        } else {
            return false;
        }
    }

    /*
     * 查询拼购商品按照拼购价格
     */
    public function queryByPriceLevel($price) {
        if(!empty($price)) {
            return $this->where('priceLevel='.$price)->select();
        } else {
            Log::write('LotteryGoodsInfoModel->queryByPriceLevel($price) 传入参数$price为空值！');
            return false;
        }
    }

    /*
     * 按照拼购开始时间降序排序
     */
    public function querySortByTime() {
        return $this->order('startDate desc')->select();
    }
}
